package com.yeshen.pmtea.net;

import android.os.AsyncTask;

import com.yeshen.pmtea.beans.News;
import com.yeshen.pmtea.callback.NewsCallback;
import com.yeshen.pmtea.utils.HttpUtils;
import com.yeshen.pmtea.utils.ParseJsonToList;

import java.util.List;

/**
 * Created by Administrator on 2016/11/15.
 */

public class NewsAsyncTask extends AsyncTask<String ,Void ,List> {
    private NewsCallback mCallback;

    public NewsAsyncTask(NewsCallback callback) {
        mCallback = callback;
    }

    @Override
    protected List doInBackground(String... params) {
        String jsonDataFromNet = HttpUtils.getJsonDataFromNet(params[0]);
        List<News> newsList = ParseJsonToList.parseJsonToNewsList(jsonDataFromNet);
        return newsList;
    }

    @Override
    protected void onPostExecute(List list) {
        super.onPostExecute(list);
        if (list!=null&&list.size()!=0){
            mCallback.callbackNews(list);
        }
    }
}
